const DEFAULT_WINDOW_WIDTH = 1920;
const DEFAULT_WINDOW_HEIGHT = 937;
const DEFAULT_WINDOW_RATE = DEFAULT_WINDOW_WIDTH / DEFAULT_WINDOW_HEIGHT;
type WindowSize = { width: number; height: number };
type WindowRateSize = { rate: number; width: number; height: number };

class WindowManager {
  // 传入可见区域的宽高，计算返回容器的宽高
  static getRegionSize(width: number, height: number): WindowSize {
    const rate = width / height;
    // 宽度比例大
    if (rate > DEFAULT_WINDOW_RATE) {
      return { width: width, height: width / DEFAULT_WINDOW_RATE };
    } else if (rate < DEFAULT_WINDOW_RATE) {
      return { width: height * DEFAULT_WINDOW_RATE, height: height };
    } else {
      return { width: width, height: height };
    }
  }

  // 返回客户区可见区域的尺寸
  static getRegionSizeFromClient() {
    const clientWidth = window.innerWidth;
    const clientHeight = window.innerHeight;
    return WindowManager.getRegionSize(clientWidth, clientHeight);
  }

  // 获取区域比例
  static getRegionRateSizeFromClient(): WindowRateSize {
    const size = WindowManager.getRegionSizeFromClient();
    return {
      rate: size.height / DEFAULT_WINDOW_HEIGHT,
      width: size.width,
      height: size.height
    };
  }
}

export { WindowManager };
